package de.dhbw.karlsruhe.picsim.model.cpu.impl;

import de.dhbw.karlsruhe.picsim.model.cpu.FileMutable;
import de.dhbw.karlsruhe.picsim.model.cpu.Interrupt;
import de.dhbw.karlsruhe.picsim.model.cpu.InterruptFacade;
import de.dhbw.karlsruhe.picsim.model.memory.impl.RegisterValueImpl;
import de.dhbw.karlsruhe.picsim.util.BitsMutable;
import de.dhbw.karlsruhe.picsim.util.impl.BitsMutableImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.NotNull;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: Apr 22, 2010
 * Time: 12:18:20 AM
 */
public final class InterruptHolderImpl implements InterruptFacade {
    private static final Log log = LogFactory.getLog(InterruptHolderImpl.class);
    private final FileMutable intCon;

    public InterruptHolderImpl(@NotNull final FileMutable intCon) {
        this.intCon = intCon;

    }

    @Override
    public void putInterrupt(@NotNull final Interrupt interrupt) {
        log.info("an event occurred which could lead to an interrupt: setting bits");
        final BitsMutable bitsMutable = new BitsMutableImpl(intCon.getData());
        bitsMutable.setBit(interrupt.getFlagPosition(), true);
        intCon.setValue(new RegisterValueImpl(bitsMutable));
    }
}

